<template>
  <el-card class="filter-card" shadow="never">
    <el-form :model="localQueryParams" inline>
      <el-form-item label="订单编号">
        <el-input
          v-model="localQueryParams.orderNumber"
          placeholder="输入订单编号"
          clearable
          style="width: 180px"
          class="input-field"
        />
      </el-form-item>
      
      <el-form-item label="客户">
        <el-select
          v-model="localQueryParams.customerId"
          clearable
          placeholder="选择客户"
          style="width: 150px"
          class="select-field"
        >
          <el-option
            v-for="customer in customerOptions"
            :key="customer.id"
            :label="customer.name"
            :value="customer.id"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="订单状态">
        <el-select v-model="localQueryParams.orderStatus" clearable placeholder="全部状态" style="width: 120px" class="select-field">
          <el-option label="待确认" value="pending" />
          <el-option label="已确认" value="confirmed" />
          <el-option label="配货中" value="picking" />
          <el-option label="已发货" value="shipped" />
          <el-option label="已完成" value="completed" />
          <el-option label="已取消" value="cancelled" />
        </el-select>
      </el-form-item>
      
      <el-form-item label="开票状态">
        <el-select v-model="localQueryParams.invoiceStatus" clearable placeholder="全部状态" style="width: 120px" class="select-field">
          <el-option label="未开票" value="uninvoiced" />
          <el-option label="已开票" value="invoiced" />
          <el-option label="已收票" value="received" />
        </el-select>
      </el-form-item>
      
      <el-form-item>
        <el-button type="primary" :icon="Search" @click="handleSearch" class="search-btn">
          查询
        </el-button>
        <el-button :icon="Refresh" @click="handleReset" class="reset-btn">
          重置
        </el-button>
        <el-button 
          link
          :icon="SetUp" 
          @click="showAdvancedFilter = !showAdvancedFilter"
          class="advanced-btn"
        >
          高级筛选
        </el-button>
      </el-form-item>
    </el-form>

    <!-- 高级筛选 -->
    <el-collapse-transition>
      <div v-show="showAdvancedFilter" class="advanced-filter">
        <el-divider content-position="left">高级筛选</el-divider>
        <el-form :model="localQueryParams" inline>
          <el-form-item label="下单时间">
            <el-date-picker
              v-model="localQueryParams.dateRange"
              type="daterange"
              range-separator="至"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="YYYY-MM-DD"
              class="date-picker-field"
            />
          </el-form-item>
          
          <el-form-item label="订单金额">
            <el-input-number
              v-model="localQueryParams.minAmount"
              :min="0"
              placeholder="最小金额"
              style="width: 120px"
              class="input-number-field"
            />
            <span class="separator">-</span>
            <el-input-number
              v-model="localQueryParams.maxAmount"
              :min="0"
              placeholder="最大金额"
              style="width: 120px"
              class="input-number-field"
            />
          </el-form-item>
          
          <el-form-item label="销售人员">
            <el-input
              v-model="localQueryParams.salesperson"
              placeholder="输入销售人员"
              clearable
              style="width: 150px"
              class="input-field"
            />
          </el-form-item>
        </el-form>
      </div>
    </el-collapse-transition>
  </el-card>
</template>

<script setup lang="ts">
import { ref, defineProps, defineEmits, watch } from 'vue'
import { Search, Refresh, SetUp } from '@element-plus/icons-vue'

const showAdvancedFilter = ref(false)

// 客户选项数据
const customerOptions = [
  { id: 1, name: '阿里巴巴集团' },
  { id: 2, name: '腾讯科技' },
  { id: 3, name: '百度公司' }
]

// 定义查询参数接口
interface QueryParams {
  orderNumber: string
  customerId: number | null
  orderStatus: string
  invoiceStatus: string
  dateRange: string[]
  minAmount: number | undefined
  maxAmount: number | undefined
  salesperson: string
  page: number
  limit: number
}

const props = defineProps<{
  queryParams: QueryParams
}>()

const emit = defineEmits<{
  (e: 'update:queryParams', value: QueryParams): void
  (e: 'search'): void
  (e: 'reset'): void
}>()

// 本地查询参数
const localQueryParams = ref({ ...props.queryParams })

// 监听父组件查询参数变化
watch(() => props.queryParams, (newVal: QueryParams) => {
  localQueryParams.value = { ...newVal }
}, { deep: true })

// 监听本地查询参数变化并同步到父组件
watch(localQueryParams, (newVal: QueryParams) => {
  emit('update:queryParams', { ...newVal })
}, { deep: true })

const handleSearch = () => {
  emit('search')
}

const handleReset = () => {
  emit('reset')
}
</script>

<style scoped>
.filter-card {
  margin-bottom: 20px;
  transition: all 0.3s ease;
}

.filter-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

.advanced-filter {
  margin-top: 16px;
}

.advanced-filter :deep(.el-divider) {
  margin: 16px 0;
}

.separator {
  margin: 0 8px;
  color: #c0c4cc;
}

/* 输入框和选择框悬停效果 */
.input-field:hover,
.select-field:hover,
.date-picker-field:hover,
.input-number-field:hover {
  transform: translateY(-1px);
  transition: all 0.3s ease;
}

/* 按钮动画效果 */
.search-btn,
.reset-btn,
.advanced-btn {
  transition: all 0.3s ease;
}

.search-btn:hover,
.reset-btn:hover,
.advanced-btn:hover {
  transform: translateY(-2px);
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

.search-btn:active,
.reset-btn:active,
.advanced-btn:active {
  transform: translateY(0);
}

/* 高级筛选按钮特殊样式 */
.advanced-btn {
  color: #409eff;
}

.advanced-btn:hover {
  color: #66b1ff;
}
</style>